using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Stock_StockInfoInRecord : Admin, IRequiresSessionState
{
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected TextBox txtSearchInfoNumber;
	protected DropDownList ddlStockStatus;
	protected Button btnSearch;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Panel pnlManage;
	protected Label lblStockNumber;
	protected Label lblInputTime;
	protected Label lblInputer;
	protected Label lblMoneyGoods;
	protected Label lblStockStatus;
	protected Label lblRemarks;
	protected GridView gvItem;
	protected Panel pnlDetail;
	private string linkHead = "";
	private string beforeUrl = "Admin_Stock_StockInfoInRecord.aspx?MenuID=5&MenuName=库存管理&FileName=库存入库记录";
	private int infoOrderID = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public int InfoOrderID
	{
		get
		{
			if (base.Request.QueryString["infoOrderID"] != null)
			{
				this.infoOrderID = Convert.ToInt32(base.Request.QueryString["infoOrderID"].Trim());
			}
			return this.infoOrderID;
		}
		set
		{
			this.infoOrderID = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(45))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Stock_StockInfoInRecord");
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(base.ActionTabInfo);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlDetail.Visible = true;
				if (this.InfoOrderID > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlDetail.Visible = false;
		this.BindData();
	}
	protected void InitPage()
	{
		HoWave.Data.Model.StockInfoOrder model = BLLInstance.BllStockInfoOrder.GetModel(this.InfoOrderID);
		if (model != null)
		{
			this.lblStockNumber.Text = model.InfoNumber;
			this.lblInputTime.Text = model.CreateDate.ToString();
			this.lblInputer.Text = model.Inputer;
			this.lblMoneyGoods.Text = model.TotalMoney.ToString();
			this.lblStockStatus.Text = BLLInstance.BllStockInfoOrder.GetStockStatusStr(model.StockStatus);
			this.lblRemarks.Text = model.Remark;
		}
		DataTable listInfoItemProductByInfoOrderID = BLLInstance.BllStockInfoOrder.GetListInfoItemProductByInfoOrderID(this.InfoOrderID);
		this.gvItem.DataSource = listInfoItemProductByInfoOrderID;
		this.gvItem.DataBind();
		for (int i = 0; i < this.gvItem.Rows.Count; i++)
		{
			string text = this.gvItem.Rows[i].Cells[2].Text;
			string text2 = this.gvItem.Rows[i].Cells[3].Text;
			if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
			{
				this.gvItem.Rows[i].Cells[5].Text = (Convert.ToInt32(text) * Convert.ToDecimal(text2)).ToString();
			}
		}
	}
	protected string GetQuery()
	{
		string text = " StockOrderType='inPurchase'";
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, StockDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, StockDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("InfoNumber");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchInfoNumber.Text = text4;
		}
		else
		{
			text4 = this.txtSearchInfoNumber.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and InfoNumber like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&InfoNumber=" + text4;
		}
		string text5 = Fetch.Get("StockStatus");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddlStockStatus.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddlStockStatus.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and StockStatus=" + text5;
			this.linkHead = this.linkHead + "&StockStatus=" + text5;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "";
		string value = this.txtSearchBeginDate.Text.Trim();
		string value2 = this.txtSearchEndDate.Text.Trim();
		if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2))
		{
			result = "StockDate desc";
		}
		return result;
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		int pageSize = this.gvManage.PageSize;
		int recordCount = BLLInstance.BllStockInfoOrder.GetRecordCount(query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		DataTable dataSource = BLLInstance.BllStockInfoOrder.GetListByPage(query, queryByOrder, startIndex, endIndex).Tables[0];
		this.gvManage.DataSource = dataSource;
		this.gvManage.DataBind();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, recordCount, "条记录&nbsp;每页" + pageSize + "条记录&nbsp;", url, true);
	}
	public string GetStatusStr(object obj)
	{
		return BLLInstance.BllStockInfoOrder.GetStockStatusStrMark(obj);
	}
	protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindData();
	}
	protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
}
